﻿using MediatR;
using Traceability.Commont.Domains.ScratchTheFat;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.Infrastructures.Interfaces;
namespace U.Enterprise.Api.Applications.EndingOnly
{
    public class ProductionScratchesupdateHandler : IRequestHandler<ProductionScratchesupdateCommond, Resqults>
    {

        private readonly IBateRepository<ProductionScratches> _ProductionScratches;

        public ProductionScratchesupdateHandler(IBateRepository<ProductionScratches> productionScratches)
        {
            _ProductionScratches = productionScratches;
        }

        public async Task<Resqults> Handle(ProductionScratchesupdateCommond request, CancellationToken cancellationToken)
        {
            
            var list=new Resqults() { Code=0};


            var query = _ProductionScratches.GetAll().FirstOrDefault(x => x.ProductionScratchesId == request.ProductionScratchesId);


            if (query != null) { 
            
                query.DocumentNumber = request.DocumentNumber;
                query.Team=request.Team;
                query.DocumentsTime=request.DocumentsTime;
                query.ProductionSummary=request.ProductionSummary;
                query.BulkSlaughterNo=request.BulkSlaughterNo;
                query.Distribution=request.Distribution;
                query.FatOil=request.FatOil;
                var Gid=    _ProductionScratches.Update(query);

                if (Gid != null) {


                    list.Code = 1;
                
                }
            }

            return list;



        }
    }
}
